import router from '@/router'
import { useUserStore } from '@/stores/user.ts'
import { message } from 'ant-design-vue'

router.beforeEach(async (to, from, next) => {
  const userStore = useUserStore()
  // if(userStore.firstLogin) {
  //   await userStore.fetchUserInfo()
  //   userStore.firstLogin = false
  // }

//   判断是否有权限
  if(to.fullPath.startsWith('/admin')) {
    if(userStore.userInfo?.userRole !== 'admin') {
      message.error('权限不足')
      next(`/?redirect=${to.fullPath}`)
    }
  }
  next()
})
